home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / hplip / ui4 / devicesetupdialog.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  8KB  |  226 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import operator
  5. import string
  6. from base.g import *
  7. from base import device, utils, pml
  8. from prnt import cups
  9. from base.codes import *
  10. from ui_utils import *
  11. from PyQt4.QtCore import *
  12. from PyQt4.QtGui import *
  13. from devicesetupdialog_base import Ui_Dialog
  14. TAB_POWER_SETTINGS = 0
  15.  
  16. class DeviceSetupDialog(QDialog, Ui_Dialog):
  17.     
  18.     def __init__(self, parent, device_uri):
  19.         QDialog.__init__(self, parent)
  20.         self.setupUi(self)
  21.         self.device_uri = device_uri
  22.         self.mq = { }
  23.         self.dev = None
  24.         self.initUi()
  25.         QTimer.singleShot(0, self.updateUi)
  26.  
  27.     
  28.     def initUi(self):
  29.         self.connect(self.CancelButton, SIGNAL('clicked()'), self.CancelButton_clicked)
  30.         self.connect(self.DeviceComboBox, SIGNAL('DeviceUriComboBox_noDevices'), self.DeviceUriComboBox_noDevices)
  31.         self.connect(self.DeviceComboBox, SIGNAL('DeviceUriComboBox_currentChanged'), self.DeviceUriComboBox_currentChanged)
  32.         self.DeviceComboBox.setFilter({
  33.             'power-settings': (operator.gt, 0) })
  34.         self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
  35.         if self.device_uri:
  36.             self.DeviceComboBox.setInitialDevice(self.device_uri)
  37.         
  38.         self.DurationComboBox.addItem(self._DeviceSetupDialog__tr('15 minutes'), QVariant(15))
  39.         self.DurationComboBox.addItem(self._DeviceSetupDialog__tr('30 minutes'), QVariant(30))
  40.         self.DurationComboBox.addItem(self._DeviceSetupDialog__tr('45 minutes'), QVariant(45))
  41.         self.DurationComboBox.addItem(self._DeviceSetupDialog__tr('1 hour'), QVariant(60))
  42.         self.DurationComboBox.addItem(self._DeviceSetupDialog__tr('2 hours'), QVariant(120))
  43.         self.DurationComboBox.addItem(self._DeviceSetupDialog__tr('3 hours'), QVariant(180))
  44.         self.connect(self.DurationComboBox, SIGNAL('activated(int)'), self.DurationComboBox_activated)
  45.         self.connect(self.OnRadioButton, SIGNAL('toggled(bool)'), self.OnRadioButton_toggled)
  46.  
  47.     
  48.     def OnRadioButton_toggled(self, b):
  49.         i = self.DurationComboBox.currentIndex()
  50.         if i == -1:
  51.             return None
  52.         (v, ok) = self.DurationComboBox.itemData(i).toInt()
  53.         if not ok:
  54.             return None
  55.         if self.power_settings == POWER_SETTINGS_EPML:
  56.             if b:
  57.                 self.setPowerSettingsEPML('999')
  58.             else:
  59.                 self.setPowerSettingsEPML(string.zfill(v, 3))
  60.         elif self.power_settings == POWER_SETTINGS_PML:
  61.             if b:
  62.                 self.setPowerSettingsPML(pml.OID_POWER_SETTINGS_NEVER)
  63.             else:
  64.                 self.setPowerSettingsPML(self.getPMLSettingsValue(v))
  65.         
  66.  
  67.     
  68.     def updateUi(self):
  69.         self.DeviceComboBox.updateUi()
  70.  
  71.     
  72.     def updatePowerSettingsUi(self):
  73.         pass
  74.  
  75.     
  76.     def DeviceUriComboBox_currentChanged(self, device_uri):
  77.         beginWaitCursor()
  78.         
  79.         try:
  80.             self.device_uri = device_uri
  81.             if self.dev is not None:
  82.                 self.dev.close()
  83.             
  84.             self.dev = device.Device(self.device_uri)
  85.             self.mq = device.queryModelByURI(self.device_uri)
  86.             self.power_settings = self.mq.get('power-settings', POWER_SETTINGS_NONE)
  87.             self.TabWidget.setTabEnabled(TAB_POWER_SETTINGS, self.power_settings != POWER_SETTINGS_NONE)
  88.             if self.power_settings == POWER_SETTINGS_EPML:
  89.                 self.updatePowerSettingsEPML()
  90.             elif self.power_settings == POWER_SETTINGS_PML:
  91.                 self.updatePowerSettingsPML()
  92.         finally:
  93.             endWaitCursor()
  94.  
  95.  
  96.     
  97.     def updatePowerSettingsEPML(self):
  98.         value = self.getPowerSettingsEPML()
  99.         if value == '999':
  100.             self.OnRadioButton.setChecked(True)
  101.             self.OffRadioButton.setChecked(False)
  102.         else:
  103.             self.OnRadioButton.setChecked(False)
  104.             self.OffRadioButton.setChecked(True)
  105.             find = int(value)
  106.             index = self.DurationComboBox.findData(QVariant(find))
  107.             if index != -1:
  108.                 self.DurationComboBox.setCurrentIndex(index)
  109.             
  110.  
  111.     
  112.     def getPowerSettingsEPML(self):
  113.         value = self.dev.getDynamicCounter(256, False)
  114.         log.debug('Current power settings: %s' % value)
  115.         self.dev.closePrint()
  116.         return value[6:9]
  117.  
  118.     
  119.     def setPowerSettingsEPML(self, value):
  120.         log.debug('Setting power setting to %s' % value)
  121.         pcl = '\x1b%%-12345X@PJL ENTER LANGUAGE=PCL3GUI\n\x1bE\x1b%%Pmech.set_battery_autooff %s;\nudw.quit;\x1b*rC\x1bE\x1b%%-12345X' % value
  122.         self.dev.printData(pcl, direct = True)
  123.         self.dev.closePrint()
  124.  
  125.     
  126.     def updatePowerSettingsPML(self):
  127.         value = self.getPowerSettingsPML()
  128.         if value == pml.OID_POWER_SETTINGS_NEVER:
  129.             self.OnRadioButton.setChecked(True)
  130.             self.OffRadioButton.setChecked(False)
  131.         else:
  132.             self.OnRadioButton.setChecked(False)
  133.             self.OffRadioButton.setChecked(True)
  134.             find = 15
  135.             if value == pml.OID_POWER_SETTINGS_15MIN:
  136.                 find = 15
  137.             elif value == pml.OID_POWER_SETTINGS_30MIN:
  138.                 find = 30
  139.             elif value == pml.OID_POWER_SETTINGS_45MIN:
  140.                 find = 45
  141.             elif value == pml.OID_POWER_SETTINGS_1HR:
  142.                 find = 60
  143.             elif value == pml.OID_POWER_SETTINGS_2HR:
  144.                 find = 120
  145.             elif value == pml.OID_POWER_SETTINGS_3HR:
  146.                 find = 180
  147.             
  148.             index = self.DurationComboBox.findData(QVariant(find))
  149.             if index != -1:
  150.                 self.DurationComboBox.setCurrentIndex(index)
  151.             
  152.  
  153.     
  154.     def getPowerSettingsPML(self):
  155.         (pml_result_code, value) = self.dev.getPML(pml.OID_POWER_SETTINGS)
  156.         self.dev.closePML()
  157.         log.debug('Current power settings: %s' % value)
  158.         return value
  159.  
  160.     
  161.     def setPowerSettingsPML(self, value):
  162.         log.debug('Setting power setting to %s' % value)
  163.         pml_result_code = self.dev.setPML(pml.OID_POWER_SETTINGS, value)
  164.         self.dev.closePML()
  165.  
  166.     
  167.     def DurationComboBox_activated(self, i):
  168.         if i == -1:
  169.             return None
  170.         (v, ok) = self.DurationComboBox.itemData(i).toInt()
  171.         if not ok:
  172.             return None
  173.         if self.power_settings == POWER_SETTINGS_EPML:
  174.             beginWaitCursor()
  175.             
  176.             try:
  177.                 self.setPowerSettingsEPML(string.zfill(v, 3))
  178.             finally:
  179.                 endWaitCursor()
  180.  
  181.         elif self.power_settings == POWER_SETTINGS_PML:
  182.             beginWaitCursor()
  183.             
  184.             try:
  185.                 self.setPowerSettingsPML(self.getPMLSettingsValue(v))
  186.             finally:
  187.                 endWaitCursor()
  188.  
  189.         
  190.  
  191.     
  192.     def getPMLSettingsValue(self, v):
  193.         x = pml.OID_POWER_SETTINGS_15MIN
  194.         if v == 15:
  195.             x = pml.OID_POWER_SETTINGS_15MIN
  196.         elif v == 30:
  197.             x = pml.OID_POWER_SETTINGS_30MIN
  198.         elif v == 45:
  199.             x = pml.OID_POWER_SETTINGS_45MIN
  200.         elif v == 60:
  201.             x = pml.OID_POWER_SETTINGS_1HR
  202.         elif v == 120:
  203.             x = pml.OID_POWER_SETTINGS_2HR
  204.         elif v == 180:
  205.             x = pml.OID_POWER_SETTINGS_3HR
  206.         
  207.         return x
  208.  
  209.     
  210.     def DeviceUriComboBox_noDevices(self):
  211.         FailureUI(self, self._DeviceSetupDialog__tr('<b>No devices that support device setup found.</b>'))
  212.         self.close()
  213.  
  214.     
  215.     def CancelButton_clicked(self):
  216.         if self.dev is not None:
  217.             self.dev.close()
  218.         
  219.         self.close()
  220.  
  221.     
  222.     def __tr(self, s, c = None):
  223.         return qApp.translate('DeviceSetupDialog', s, c)
  224.  
  225.  
  226.